﻿CREATE VIEW dbo.StepRecursive
AS
WITH    cte ( ParentStep_StepID, StepID,StepLevel ) 
              AS ( SELECT   StepID, 
                            StepID,
							0 as Level
                   FROM     dbo.Steps where ParentStep_StepID is null
                   UNION ALL 
                   SELECT   cte.ParentStep_StepID,e.StepID  
							, StepLevel + 1 as StepLevel
                   FROM     cte 
                            INNER JOIN dbo.Steps AS e ON cte.StepID = e.ParentStep_StepID
                 )  

				 select * FROM cte 
